<?php
/**
 * Created by PhpStorm.
 * User: LiuYang
 * Date: 2017/3/9
 * Time: 19:37
 */

namespace app\api\behavior;

use think\Exception;
use think\Response;

class CORS
{
    public function appInit(){

        $origin = request()->server('HTTP_ORIGIN') ? request()->server('HTTP_ORIGIN') : '';

//        $allow_origin = [
//            'http://www.dj1.com',
//            'http://djtz.test',
//            'http://p6360.com',
//            'http://www.p6360.com',
//            'https://k6920.com',
//            'https://www.k6920.com',
//            'http://10.20.32.101:8080',
//            'http://10.20.32.176:8080',
//        ];
        $origin = '*';
//        if (in_array($origin, $allow_origin)) {
            header('Access-Control-Allow-Origin: '.$origin.'');
            header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
            header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
//        }
        if(request()->isOptions()){
            exit("ok");
        }

    }

}